﻿/*-------------------------------------------------------------------------
* 命名空间: PrismCommandSimple.ViewModels/MainViewModel
* 类       名: MainViewModel
* 功      能:  TD
* 时      间:  2023/12/21 11:52:29
* 版      本:  V1.0
* 作      者:  Fioman
* 格      言:  Talk is cheap,show me the code ^_^
*-------------------------------------------------------------------------*/
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using PrismCommandSimple.Views;
using System;

namespace PrismCommandSimple.ViewModels
{
    public class MainViewModel : BindableBase
    {
        private readonly IRegionManager _regionManager;

        private string? commandParameterVal;

        public string? CommandParameterVal
        {
            get { return commandParameterVal; }
            set
            {
                commandParameterVal = value;
                RaisePropertyChanged();
            }
        }

        public MainViewModel(IRegionManager regionManager)
        {
            ShowViewACommandNoParameter = new DelegateCommand(DoShowViewA);
            _regionManager = regionManager;

            commandParameterVal = "命令参数模拟值";
            ShowViewBWithParameter = new DelegateCommand<string>(DoShowViewB);

            DoTwoCommmand = new CompositeCommand();
            DoTwoCommmand.RegisterCommand(ShowViewACommandNoParameter);
            DoTwoCommmand.RegisterCommand(ShowViewBWithParameter);
        }



        public DelegateCommand ShowViewACommandNoParameter { get; private set; }
        private void DoShowViewA()
        {
            _regionManager.Regions["ContentRegion"].RequestNavigate(nameof(ViewA));
        }

        public DelegateCommand<string> ShowViewBWithParameter { get; private set; }
        private void DoShowViewB(string parameter)
        {
            _regionManager.Regions["ContentRegion"].RequestNavigate(nameof(ViewB));
        }


        public CompositeCommand DoTwoCommmand { get; private set; }

    }
}
